﻿using System.Collections;
using System.Collections.Generic;
using Pb;
using UnityEngine;

public class E_MailModel : MonoBehaviour
{
    public GameObject CloseBtn;
    public GameObject E_MailPanel;
    public List<AuthMessageContent> msg_list = new List<AuthMessageContent>();
    public UIGrid NGUIGrid;
    private void Awake()
    {
        UIEventListener.Get(CloseBtn).onClick = ButtonClick;
    }
    

    // Use this for initialization
    void Start()
    {
        Debug.Log("邮箱已经打开 " + msg_list.Count);
        LoadMsg();

    }
    public void OnBackBtnClick()
    {
        Destroy(gameObject);
    }

    void LoadMsg()
    {
        if (msg_list.Count > 0)
        {
            int tempcount = msg_list.Count;
            for (int i = 0; i < tempcount; i++)
            {
                GameObject _gridItem = (GameObject)Instantiate(Resources.Load(HallPrafabPath.E_MailItem));
                _gridItem.name = i + 1.ToString();
                _gridItem.transform.parent = NGUIGrid.gameObject.transform;
                _gridItem.transform.localPosition = new Vector3(0, 0, 0);
                _gridItem.transform.localScale = new Vector3(1, 1, 1);
                EmailItem item = _gridItem.GetComponent<EmailItem>();
                Debug.Log("isread" + msg_list[i].IsRead);
                //item.ReadStatus.SetActive(!msg_list[i].IsRead);
                item.isRead = msg_list[i].IsRead;
                item.HaveReadIcon.SetActive(msg_list[i].IsRead);
                item.NotReadIcon.SetActive(!msg_list[i].IsRead);
                item.contentStr = msg_list[i].Content;
                item.time = msg_list[i].CreateTime;
                item.EmailItemContent.text = "[e76505]" + msg_list[i].Content;
                item.id = msg_list[i].Id;
            }

        }
        else
        {
            GameObject empty = NGUITools.AddChild(gameObject, (GameObject)Resources.Load(HallPrafabPath.Empty));
        }
    }
    void ButtonClick(GameObject button)
    {
        if (button.name == "CloseBtn")
        {
            Destroy(E_MailPanel);
        }
    }

}
